package com.dlc.shop.sys.platform.listener;

import com.dlc.shop.bean.event.GetPermissionEvent;
import com.dlc.shop.security.common.util.AuthUserContext;
import com.dlc.shop.sys.common.service.SysMenuService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author gaozijie
 * @since 2023-12-14
 */
@Component
@AllArgsConstructor
public class GetPermissionEventListener {
    private final SysMenuService sysMenuService;

    @EventListener(GetPermissionEvent.class)
    public void getShopSuperAdmin(GetPermissionEvent event) {
        Set<String> shopPermissions
                = sysMenuService.getUserPermissions(AuthUserContext.getSysUserId());
        event.setPerms(shopPermissions);
    }
}
